<template>
  <!-- 计量设备检定记录 -->
  <div class="equipment-verification-record-con">
    <a-card :bordered="false">
      <title-name :title="title"></title-name>
      <b-table ref="table" bordered :columns="columns" :request="recordTableData" row-key="id">
        <span slot="serial" slot-scope="text, record, index">{{ index + 1 }}</span>
        <template slot="mdInfoAppraisalFileVOList" slot-scope="text, record">
          <file-link :fileList="record.mdInfoAppraisalFileVOList"></file-link>
        </template>
      </b-table>
    </a-card>
  </div>
</template>

<script>
import api from '@/api/quality/ownEquipmentLedger' // api
import {
  checkType,
  checkStatusArr
} from '@/views/quality/equipmentManagement/constant/dictionary'
import moment from 'moment'

export default {
  name: "equipmentVerificationRecord",
  props: {
    title: {
      type: String,
      default() {
        return '计量设备检定记录'
      }
    },
    // api请求方法
    apiName: {
      type: String,
      default: () => 'getPageMdInfoAppraisalRecord'
    },
    //查询参数
    queryParam: {
      type: Object,
      default: () => { }
    }
  },
  data() {
    return {
      api,
      columns: [
        {
          title: '序号',
          dataIndex: 'serial',
          scopedSlots: { customRender: 'serial' },
          width: 70
        },
        {
          title: '本次检定日期',
          dataIndex: 'currentAppraisalDate',
          customRender: (text) => {
            return text&&moment(text).locale('zh-cn').format('YYYY-MM-DD')
          }
        },
        {
          title: '检定方式',
          dataIndex: 'appraisalType',
          customRender(e) {
            const obj = checkType.find((v) => v.value === e)
            return Object.keys(obj).length ? obj.label : null
          }
        },
        {
          title: '检定结果',
          dataIndex: 'appraisalStatus',
          customRender(e) {
            const obj = checkStatusArr.find((v) => v.value === e)
            return Object.keys(obj).length ? obj.label : null
          }
        },
        {
          title: '检定单位',
          dataIndex: 'appraisalCompany',
          ellipsis: true,
        },
        {
          title: '检定详情',
          dataIndex: 'appraisalDetail',
          ellipsis: true,
        },
        {
          title: '填写人',
          dataIndex: 'fillInUserName',
          ellipsis: true,
        },
        {
          title: '填写时间',
          dataIndex: 'fillInTime',
          customRender: (text) => {
            return text&&moment(text).locale('zh-cn').format('YYYY-MM-DD')
          }
        },
        {
          title: '附件',
          dataIndex: 'mdInfoAppraisalFileVOList',
          ellipsis: true,
          scopedSlots: { customRender: 'mdInfoAppraisalFileVOList' },
        },
      ],
      recordTableData: async (parameter) => {
        let { pageNo, pageSize } = parameter;
        let params = {
          pageNum: pageNo,
          pageSize
        };
        const requestParameters = Object.assign({}, params, { param: this.queryParam })
        return this.api[this.apiName](requestParameters).then((res) => {
          if (res.code === '0') {
            return { code: 200, data: res.data?.list, totalSize: res.data?.total }
          }
        })
      },
    }
  }
}
</script>